package com.vaadin.tutorial.crm.backend.repository;

import com.vaadin.tutorial.crm.backend.entity.SysUser;
import com.vaadin.tutorial.crm.backend.entity.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @Description:
 * @Author: Fan
 * @Date: 2021/1/18 20:40
 * @Version 1.0
 */
public interface SysUserRepository extends JpaRepository<SysUser, Long> {
    /**
     * 根据登录用户名查询用户信息
     *
     * @param username
     * @return
     */
    @Query("select u from SysUser u where u.username = ?1")
    SysUser getUserByUsername(String username);

    /**
     * 根据用户名查询用户信息
     *
     * @param searchTerm
     * @return
     */
    @Query("select u from SysUser u " +
            "where u.username like concat('%', :searchTerm, '%') ")
    List<SysUser> search(@Param("searchTerm") String searchTerm);
}
